package main

import (
	"../fileutil"
	"../picutil"
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
)

func main() {

	scanner := bufio.NewReader(os.Stdin)
	fmt.Println("请输入图片目录")
	lineBytes, _, _ := scanner.ReadLine()
	picturePath := string(lineBytes)

	ClassifyPicture2(picturePath)

}

func ClassifyPicture2(picturePath string) {
	// 创建输出目录
	pic1080OutPath, _ := fileutil.MkDir(picturePath, "1080")
	pic1920OutPath, _ := fileutil.MkDir(picturePath, "1920")

	pic1080List := make([]string, 0)
	pic1920List := make([]string, 0)

	success := 0
	fail := 0
	fmt.Printf("开始处理。。。")

	// 处理图片
	pictures, _ := ioutil.ReadDir(picturePath)
	for _, picture := range pictures {
		fileName := picture.Name()
		fileutil.DealDesktop(picturePath, fileName)
		fileFullPath := filepath.Join(picturePath, fileName)
		if !fileutil.IsFile(fileFullPath) {
			continue
		}
		config := picutil.Config(fileFullPath)
		g := float32(config.Height) / float32(config.Width)
		if g > 0.5625 {
			pic1920List = append(pic1920List, fileName)
		} else {
			pic1080List = append(pic1080List, fileName)
		}
	}

	// 移动图片

	success1920, fail1920 := fileutil.MoveFiles(pic1920List, picturePath, pic1920OutPath)
	fmt.Println()

	success1080, fail1080 := fileutil.MoveFiles(pic1080List, picturePath, pic1080OutPath)
	fmt.Println()

	success = success1920 + success1080
	fail = fail1920 + fail1080

	fmt.Println()
	fmt.Println("---------------------------")
	fmt.Printf("成功： %d， 失败： %d\n", success, fail)
	fmt.Println("END!")
}
